package ls.cloud.register;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2016/12/29.
 */
@Data
public class ServerInfo {
    private String wan;
    private String lan;

    private List<String> roles = Collections.emptyList();//未使用

//    private


    private long startupTime = System.currentTimeMillis();


    public byte[] toBytes() {
        try {
            return JSON.toJSONString(this).getBytes("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException("wtf");
        }
    }

    public static ServerInfo parse(byte[] bytes) {
        try {
            return JSON.parseObject(new String(bytes, "utf-8"), ServerInfo.class);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException("wtf");
        }


    }

}
